package com.md.value.enums;

import com.md.base.EnumBase;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author 刘骄阳
 * 2022-04-07 17:56
 */
@Getter
@AllArgsConstructor
public enum AuthEnum implements EnumBase {

  /**
   * 无需权限
   */
  OPEN(0, "OPEN"),

  /**
   * 需要权限
   */
  NEED(1, "NEED"),

  /**
   * 禁止访问
   */
  PROHIBIT(2, "PROHIBIT");

  static final Map<Integer, AuthEnum> ENUM_MAP = Arrays.stream(AuthEnum.values())
    .collect(Collectors.toMap(EnumBase::getCode, e -> e));
  static final Map<String, AuthEnum> ENUM_MAP_STRING = Arrays.stream(AuthEnum.values())
    .collect(Collectors.toMap(EnumBase::getMessage, e -> e));
  private final Integer code;
  private final String message;

  public static AuthEnum of(final String message) {
    return ENUM_MAP_STRING.get(message);
  }

  public static AuthEnum of(final Integer code) {
    return ENUM_MAP.get(code);
  }
}
